package com.giantlizard.cloud.system.controller;

import com.giantlizard.cloud.base.generics.R;
import com.giantlizard.cloud.system.entity.SysPosition;
import com.giantlizard.cloud.system.service.SysPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统-岗位 控制器
 */
@RestController
@RequestMapping("/position")
@Api(value = "系统-岗位", tags = {"系统-岗位"})
public class SysPositionController {

    private final SysPositionService sysPositionService;

    public SysPositionController(SysPositionService sysPositionService) {
        this.sysPositionService = sysPositionService;
    }

    @ApiOperation(value = "获取所有岗位")
    @GetMapping("/list")
    public R<List<SysPosition>> list() {
        return R.ok(sysPositionService.list());
    }

    @ApiOperation(value = "根据ID获取岗位")
    @GetMapping("/{id}")
    public R<SysPosition> getById(@ApiParam(name = "id", required = true, value = "岗位ID") @PathVariable String id) {
        return R.ok(sysPositionService.getById(id));
    }

    @ApiOperation(value = "新增岗位")
    @PostMapping
    public R<Boolean> add(@RequestBody SysPosition sysPosition) {
        return R.ok(sysPositionService.save(sysPosition));
    }

    @ApiOperation(value = "更新岗位")
    @PutMapping
    public R<Boolean> update(@RequestBody SysPosition sysPosition) {
        return R.ok(sysPositionService.updateById(sysPosition));
    }

    @ApiOperation(value = "删除岗位")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@ApiParam(name = "id", required = true, value = "岗位ID") @PathVariable String id) {
        return R.ok(sysPositionService.removeById(id));
    }
} 